<template>
  <div>
    <van-cell
      v-for="item in searchSuggest"
      :key="item.id"
      :title="item.name"
      @click="onSearch(item.name)"
      center
    >
      <template #icon>
        <van-icon class="icon" name="search" />
      </template>
    </van-cell>
  </div>
</template>

<script>
import eventBus from '@/event-bus';

export default {
  computed: {
    searchSuggest () {
      return eventBus.searchSuggest;
    },
  },
  methods: {
    onSearch (v) {
      // 跳转至搜索结果页面
      this.$router.push({
        name: 'search-list',
        query: {
          searchValue: v,
        },
      });
      // 搜索最佳匹配
      eventBus.$emit('updateSearchMultimatch', v);
      // 获取搜索结果
      eventBus.$emit('updateSearchList', v);
    },
  },
}
</script>

<style scoped>
.icon {
  margin-right: 8px;
}
</style>
